use axum::Json;
use serde_json::Value;
use base64::{ engine::general_purpose, Engine as _};

use crate::code;

pub fn encode(bytes:Vec<u8>) -> String {
    general_purpose::STANDARD.encode(bytes) 
}
pub fn decode(b64:Option<String>) -> Result<Vec<u8>, Json<Value>> {
    if let Some(f) = b64 {
        match general_purpose::STANDARD.decode(f) {
            Ok(f) => Ok(f),
            Err(e) => Err(code::sys_(e.to_string()))
        }
    } else{
        Err(code::err_("文件不存在"))
    }
}